<template>
  <div>Excel</div>
  <a-table :columns="columns" :dataSource="data">
    <template #bodyCell="{ column, record }">
      <template v-if="column.key === 'image'">
        <img :src="record.image" alt="">
      </template>
    </template>
  </a-table>
  <a-button @click="downloadExcel()">下载</a-button>
</template>

<script lang="ts">
// import * as exportExcel from './excel.js'
// import exportExcel = require('./excel');
// const exportExcel:any = require('./excel')
// import exportExcel = require('./excel')
import { exportExcel } from './excel'
export default {
  name: 'Exceljs',
  setup () {
    const columns:any = [{
      title: '标题',
      key: 'title',
      dataIndex: 'title'
    }, {
      title: '时间',
      types: 'date',
      key: 'date',
      dataIndex: 'date'
    }, {
      title: '描述',
      key: 'describe',
      dataIndex: 'describe'
    }, {
      title: '图片',
      types: 'image',
      key: 'image',
      dataIndex: 'image'
    }]
    const data:any = [{
      id: 1,
      title: 'test1',
      date: '2020-10-10',
      describe: '这是红色的',
      image: 'http://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/img/vip-entry.a14de9c.png'
    }, {
      id: 2,
      title: 'test2',
      date: '2020-10-12',
      describe: '这是蓝色的',
      image: 'http://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/img/vip-entry.a14de9c.png'
    }]
    const downloadExcel = () => {
      exportExcel(columns, data, 'bill')
    }
    return {
      columns,
      data,
      downloadExcel
    }
  },
  methods: {
  }
}
</script>

<style>
</style>
